﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;
using BUS;

namespace _1173033
{
    public partial class Form1 : Form
    {
        public string manv = "%%";
        public string hoten = "%%";
        public string chucvu = "%%";
        public string namvaolam = "%%";
        public string bangcap = "%%";
        public string phongban = "%%";
      
        public Form1()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataTable dt = BangCapBUS.LoadDSBC();
            foreach (DataRow dr in dt.Rows)
            {
                cbbBangCap.Items.Add(dr[1]);
            }
            DataTable dt1 = BoPhanBUS.LoadDSBP();
            foreach (DataRow dr1 in dt1.Rows)
            {
                cbbPhongBan.Items.Add(dr1[1]);
            }
            DataTable dt2 = ChucVuBUS.LoadDSCV();
            foreach (DataRow dr2 in dt2.Rows)
            {
                cbbChucVu.Items.Add(dr2[1]);
            }
            DataTable dt3 = NhanVienBUS.LoadDSNhanVien();
            foreach (DataRow dr3 in dt3.Rows)
            {
                cbbNamVaoLam.Items.Add(dr3[4]);
            }
        }

        private void txtMaNV_Click(object sender, EventArgs e)
        {
            if (txtMaNV.Text == "")
                txtMaNV.Focus();
        }

        private void txtHoTen_Click(object sender, EventArgs e)
        {
            if (txtHoTen.Text == "")
                txtHoTen.Focus();
        }
        private void btnTraCuu_Click(object sender, EventArgs e)
        {
            if (txtMaNV.Text == "" && txtHoTen.Text == "" && cbbChucVu.Text == "" && cbbNamVaoLam.Text == "" && cbbPhongBan.Text == "" && cbbBangCap.Text == "")
            {
                MessageBox.Show("Hãy Nhập Thông Tin Bạn Muốn Tra Cứu");
                return;
            }
            if (txtMaNV.Text != "")
            {
                manv = "%" + txtMaNV.Text + "%";
            }
            else
            {
                manv = "%%";
            }

            if (txtHoTen.Text != "")
            {
                hoten = "%" + txtHoTen.Text + "%";
            }
            else
            {
                hoten = "%%";
            }
            if (cbbChucVu.Text != "")
            {
                chucvu = "%" + cbbChucVu.Text + "%";
            }
            else
            {
                chucvu = "%%";
            }
            if (cbbBangCap.Text != "")
            {
                bangcap = "%" + cbbBangCap.Text + "%";
            }
            else
            {
                bangcap = "%%";
            }
            if (cbbPhongBan.Text != "")
            {
                phongban = "%" + cbbPhongBan.Text + "%";
            }
            else
            {
                phongban = "%%";
            }
            if (cbbNamVaoLam.Text != "")
            {
                namvaolam = "%" + cbbNamVaoLam.Text + "%";
            }
            else
            {
                namvaolam = "%%";
            }
            DataTable dt = NhanVienDAO.TimNhanVien(manv, hoten, chucvu,namvaolam,bangcap, phongban);
            dgvNhanVien.DataSource = dt;
            txtHoTen.Clear();
            txtMaNV.Clear();
            cbbBangCap.Text = "";
            cbbChucVu.Text = "";
            cbbNamVaoLam.Text = "";
            cbbPhongBan.Text = "";
        }
    }
}
